package com.fish.start.animation.views;


import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.Gravity;

import com.fish.start.animation.AnimationSet;
import com.fish.start.animation.R;
import com.fish.start.animation.StartAnimationActivity;
import com.fish.start.animation.Attr.AbstractWay;
import com.fish.start.animation.effect.BitmapWayEffect;
import com.fish.start.animation.effect.ZAlpha;
import com.fish.start.animation.effect.ZDisplacement;
import com.fish.start.animation.effect.ZRotate;
import com.fish.start.animation.effect.ZScale;
import com.fish.start.animation.effect.ZSpeed;

public class TheFishGameView extends FishView {
	private static final String tag = TheFishGameView.class.getSimpleName();
	public static  final int FISH_GAME_VIEW_DRAW_STOP = 100;
	public static  final int  FISH_GAME_VIEW_DRAW_DESTORY = 101;
	private StartAnimationActivity mStartAnimationActivity;
	private AbstractWay mAnimationAttr;
	
	public TheFishGameView(Context aStartAnimationActivity) {
		super(aStartAnimationActivity);
 		mStartAnimationActivity = (StartAnimationActivity)aStartAnimationActivity;
		setCanvasDrawInterface(this);
		setAnimatonCallBack(this);
		setHandler(mStartAnimationActivity.mHahdler);
	}
	public TheFishGameView(Context context, AttributeSet attrs) {
		super(context, attrs);
 		mStartAnimationActivity = (StartAnimationActivity)context;
		setCanvasDrawInterface(this);
		setAnimatonCallBack(this);
		setHandler(mStartAnimationActivity.mHahdler);
	}
	@Override
	public void draw(Canvas aCanvas){
		try{
			super.draw(aCanvas);
			mAnimationAttr = mAnimationSet.pop();
			drawCanvas(aCanvas ,mAnimationAttr);
		}catch(Exception e){
			handlerException(e);
		}
	}
	@Override
	public void drawSelf(Canvas aCanvas) {
		try{
			super.drawSelf(aCanvas);
		}catch(Exception e){
			handlerException(e);
		}
	}
	@Override
	public void produceAnimation(AnimationSet mAnimations) {
		try{
			AbstractWay aw = new BitmapWayEffect(this,					
					BitmapFactory.decodeStream(getResources().openRawResource(R.raw.the_fish_game),null,getOpt()));
			aw.setLayoutGravity(Gravity.CENTER);
			ZAlpha aZAlpha = new ZAlpha(new ZSpeed(0.0f,20.0f),new int[]{0,255});
			ZScale aZScale = new ZScale(new ZSpeed(0.01f,0.00008f),new float[]{0.02f,1.0f});
			ZDisplacement aZDisplacement = new ZDisplacement(new ZSpeed(90.0f,0.0f), 
					new float[] {0.0f, 0.0f}, 
					new float[] {(float) mScreenWidth / 2, (float) mScreenHeight / 2 });
			ZRotate aZRotate = new ZRotate(new ZSpeed(0.0f,-25.0f),new float[]{0,720});
			aw.setAlpha(aZAlpha);
			aw.setScale(aZScale);
			aw.setDisplacement(aZDisplacement);
			aw.setRotate(aZRotate);
			aw.createAnimatons(mAnimations);
		}catch(Exception e){
			handlerException(e);
		}
	}
	
	@Override
	public void onStop() {
		handler(FISH_GAME_VIEW_DRAW_STOP,null);
	}
	@Override
	public void onDestory() {
		super.onDestory();
		handler(FISH_GAME_VIEW_DRAW_DESTORY,null);		
	}
}
